use crate::errors::MyResult;
//use gloo::console::log;
//use crate::errors::{ErrLogger, MyResult};
use crate::models::{Data, Note, NoteProfile};
use crate::utils::api::{delete, get, get_with_param, post};

pub async fn save_content(id: u64, note_version: u64, content: &str) -> MyResult<Data<u64>> {
    let data: MyResult<Data<u64>> = post(
        "notes",
        Note {
            id,
            version: note_version,
            content: content.to_string(),
        },
    )
    .await;
    data
}

pub async fn get_note_profiles() -> MyResult<Data<Vec<NoteProfile>>> {
    let data: MyResult<Data<Vec<NoteProfile>>> = get("note_profiles").await;
    data
}

pub async fn get_note_content(id: u64) -> MyResult<Data<Note>> {
    let data: MyResult<Data<Note>> = get_with_param("notes", [("id", id.to_string())]).await;
    data
}

pub async fn delete_note(note_id: u64) -> MyResult<()> {
    delete("notes", [("id", note_id.to_string())]).await
}
